var EventEmitter = require('events').EventEmitter;
var mysql      = require('mysql');
var event = new EventEmitter();
event.on('dataReceive', function (data) {
    console.log('data:'+data);
});

var connection = mysql.createConnection({
  host     : '127.0.0.1',
  user     : 'root',
  password : 'root',
  database : 'adminstore'
});
 
connection.connect();
 
connection.query('SELECT * from menu', function (error, results, fields) {
  if (error) throw error;
  for (const key in fields) {
    //console.info(key);
  }
  results.forEach(element => {
    console.log('The solution is: ',element.id);
    event.emit("dataReceive",element);
  });
});

connection.end();